function getPuduct (data,val) {
	let newArray = [];
	for (let item of data) {
		for (let todo of item[val.child]) {
			newArray.push({
				productId: todo[val.getParam[0]],
				skuId: todo[val.getParam[1]],
				promotionPrice: todo[val.getParam[2]],
				isMustBuy: item[val.getParam[3]]
			})
		}
	}
  return newArray
}
const plusZero = (value) => {
  return value < 10 ? "0" + value : value
}
function formatDate  (value, hasTime){
   if (!value) return "";
   if (typeof value === 'string') {
    value = value.replace(/\-/g, "/");
   }
   value = new Date(value);
   let result = "";
   let year = value.getFullYear();
   let month = value.getMonth() + 1;
   let day = value.getDate();
   month = plusZero(month);
   day = plusZero(day);
   result = year + "-" + month + "-" + day;
   if (hasTime) {
     let hour = value.getHours();
     let minute = value.getMinutes();
     let seconds = value.getSeconds();
     hour = plusZero(hour);
     minute = plusZero(minute);
     seconds = plusZero(seconds)
     result +=" " + hour + ":" + minute + ":" + seconds
   }
   return result
} 
function setSelectList (data, val) {
	for (let item of data) {
		item.label = item[val.label]
		item.value = item[val.value]
	}
	return data;
}
function setCascaderList (data, val) {
	for (let item of data) {
		item.label = item[val.mt][val.label]
		item.value = item[val.mt][val.value]
		item.children = item[val.child]
		if (item[val.child] && item[val.child].length) {
			setCascaderList(item[val.child], val)
		}
	}
}
function getValue (data,val) {
	let newArray=[];
	data.map(function(item,index,array){
		newArray.push({m:item[val.index],n: '0'})
	})
	return newArray;
 } 
function getValue1 (data,val) {
	let newArray=[];
	data.map(function(item,index,array){
		newArray.push({'denomination': item[val.index1], 'useCondition': item[val.index2], 'validityDays': item[val.index3]})
	})
	return newArray;
}
export {
	getPuduct,
	formatDate,
	setSelectList,
	setCascaderList,
	getValue,
	getValue1
}